﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Administrator_loaisp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        pager.PageSize = 15;
        Criteria c = new Criteria();
        if (txt_tenlo.Text != "")
        {
            c.add(Condition.AND,Tbl_LoaiSP_Columns.TenLoai, Condition.LIKE,
                txt_tenlo.Text);
        }

        int total = 0;
        Tbl_LoaiSP_Collection loaiCollection = Tbl_LoaiSP_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize, Tbl_LoaiSP_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = loaiCollection;
        Repeater1.DataBind();
        pager.ItemCount = total;


    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_LoaiSP_Entities loai = (Tbl_LoaiSP_Entities)e.Item.DataItem;
            HyperLink hyp_tenloai = (HyperLink)e.Item.FindControl("hyp_tenloai");

            Literal lit_maloai = (Literal)e.Item.FindControl("lit_maloai");
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");
            HiddenField hd_madn = (HiddenField)e.Item.FindControl("hd_maloai");

            hyp_tenloai.NavigateUrl = "~/Administrator/sanpham.aspx?id=" + loai.STT.ToString();
            lit_maloai.Text = loai.MaLoai.ToString();
            lit_stt.Text = loai.STT.ToString();


            HyperLink hpl_sua = (HyperLink)e.Item.FindControl("hpl_sua");
            hpl_sua.ImageUrl = "~/Photos/modify_icon.jpg";
            hpl_sua.NavigateUrl = "~/Administrator/loaisp_Update.aspx?id=" + loai.STT.ToString();

            HyperLink hpl_xoa = (HyperLink)e.Item.FindControl("hpl_xoa");
            hpl_xoa.ImageUrl = "~/Photos/del_icon.jpg";
            hpl_xoa.NavigateUrl = "~/Administrator/delete.aspx?id=" + loai.STT.ToString();

        }
    }

    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        LoadData();
    }
}
